<template>
  <div class="order-cost-form">
    <div :style="isChange ? '' : 'display: none;'">
      <div class="cost_item">
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">区域</div>
          <div class="adjustOrderItem_right">
            <el-select v-model="areaIds" placeholder="请选择" @change="changeArea"
              :disabled="true">
              <el-option v-for="(item, index) in areaList" :key="index" :label="item.sysValueName"
                :value="item.id"></el-option>
            </el-select>
          </div>
        </div>
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">商务</div>
          <div class="adjustOrderItem_right">
            <el-select v-model="bussinessUsername" placeholder="请选择" @change="changeBusiness"
              :disabled="true">
              <el-option v-for="(item, index) in bussinessUserList" :key="index" :label="item.sysValueName"
                :value="item.sysValueName"></el-option>
            </el-select>
          </div>
        </div>
      </div>
      <div class="cost_item">
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">品牌名称</div>
          <div class="adjustOrderItem_right">
            <!-- <el-input v-model="brands"  label="品牌名称"></el-input> -->
            <el-select v-model="brands" placeholder="请选择" @change="changeBrands" filterable
              :filter-method="(value) => { remoteMethodBrands(value) }" v-el-select-loadmore="loadMoreBrands"
              @focus="remoteMethodBrands('')"
              :disabled="userInfo.role && (userInfo.role.includes(40) || userInfo.role.includes(55))"
              :loading="brandsStopLoading">
              <el-option v-for="(item, index) in brandsList" :key="index" :label="item.brandsName"
                :value="item.brandsName"></el-option>
            </el-select>
          </div>
        </div>
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">项目名称</div>
          <div class="adjustOrderItem_right">
            <el-input v-model="name" label="项目名称" @input="doGetHasAddProjectName" id="asNameInp"></el-input>
            <div v-if="sureLoading" style="color: red;">项目名称已被添加</div>
          </div>
        </div>
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">客户公司名称</div>
          <div class="adjustOrderItem_right">
            <el-input v-model="projectName" label="客户公司名称"></el-input>
          </div>
        </div>
      </div>
      <div class="cost_item">
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">客户负责人</div>
          <div class="adjustOrderItem_right">
            <el-input v-model="brandsUsername" label="客户负责人"></el-input>
          </div>
        </div>
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">品名</div>
          <div class="adjustOrderItem_right">
            <el-input v-model="productName" label="品名"></el-input>
          </div>
        </div>
      </div>
      <div class="cost_item">
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">品类</div>
          <div class="adjustOrderItem_right">
            <el-select v-model="cateIdList" placeholder="请选择" multiple>
              <el-option v-for="(item, index) in cateList" :key="index" :label="item.sysValueName"
                :value="item.id"></el-option>
            </el-select>
          </div>
        </div>
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">执行负责人</div>
          <div class="adjustOrderItem_right">
            <el-select v-model="permissionUsername" placeholder="请选择"
              :disabled="userInfo.role && userInfo.role.includes(50)">
              <el-option v-for="(item, index) in permissionUserList" :key="index" :label="item.username"
                :value="item.username"></el-option>
            </el-select>
          </div>
        </div>
      </div>
      <div class="cost_item">
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">合同编号</div>
          <div class="adjustOrderItem_right">
            <el-input v-model="orderNo" label="合同编号"></el-input>
          </div>
        </div>
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">备注</div>
          <div class="adjustOrderItem_right">
            <el-input v-model="projectRemark" type="textarea" :rows="2" label="备注" maxlength="250"
              show-word-limit></el-input>
          </div>
        </div>
      </div>
      <div class="cost_item_solid" v-if="operationList.includes('editInvoice')"></div>
      <div class="cost_item" v-if="operationList.includes('editInvoice')">
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">开票公司</div>
          <div class="adjustOrderItem_right">
            <el-select v-model="invoiceCompany" placeholder="请选择">
              <el-option v-for="(item, index) in invoiceCompanyList" :key="index" :label="item.sysValueName"
                :value="item.id"></el-option>
            </el-select>
          </div>
        </div>
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">开票金额</div>
          <div class="adjustOrderItem_right">
            <el-input-number v-model="invoicePrice" :precision="2" :min="0" label="开票金额"></el-input-number>
          </div>
        </div>
      </div>
      <div class="cost_item_solid" v-if="operationList.includes('editGoodArrival')"></div>
      <div class="cost_item" v-if="operationList.includes('editGoodArrival')">
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">到货进度</div>
          <div class="adjustOrderItem_right">
            <el-input v-model="goodArrivalStatus" label="到货进度"></el-input>
          </div>
        </div>
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">到货详情</div>
          <div class="adjustOrderItem_right">
            <el-input v-model="goodArrivalMsg" label="到货详情"></el-input>
          </div>
        </div>
      </div>
      <div class="cost_item" v-if="operationList.includes('editGoodArrival')">
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">执行进度</div>
          <div class="adjustOrderItem_right">
            <el-select v-model="executionProgressId" placeholder="请选择">
              <el-option v-for="(item, index) in executionProgressList" :key="index" :label="item.sysValueName"
                :value="item.id"></el-option>
            </el-select>
          </div>
        </div>

        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left">到货仓库</div>
          <div class="adjustOrderItem_right">
            <el-select v-model="arrivalWarehouseId" placeholder="请选择">
              <el-option v-for="(item, index) in arrivalWarehouseList" :key="index" :label="item.sysValueName"
                :value="item.id"></el-option>
            </el-select>
          </div>
        </div>
      </div>
      <div class="cost_item" v-if="operationList.includes('editGoodArrival')">
        <div class="adjustOrderItem">
          <div class="other">
            <div class="other-top">
              <el-button type="warning" size="mini" @click="projectLookEditDisabledHandler(1)"
                v-if="projectLookEditDisabled">修改</el-button>
              <el-button size="mini" @click="projectLookEditDisabledHandler(2)" v-else>取消</el-button>
            </div>
            <div class="other-bottom">
              <div class="bottom-item">
                <div class="bottom-label">到货状态</div>
                <div class="bottom-content">
                  <el-select :disabled="projectLookEditDisabled" v-model="arrivalProgressId" @change="arrivalChange"
                    placeholder="请选择">
                    <el-option v-for="(item, index) in arrivalProgressList" :key="index" :label="item.sysValueName"
                      :value="item.id"></el-option>
                  </el-select>
                </div>
              </div>
              <div class="bottom-item">
                <div class="bottom-label">
                  到货百分比(%) <br>
                  未到货百分比{{
                  100 - hasArrivalRate > 0 ? 100 - hasArrivalRate : 0
                  }}%
                </div>
                <div class="bottom-content">
                  <el-input-number :disabled="projectLookEditDisabled" v-model="arrivalRate" :precision="2" :min="0"
                    :max="100 - hasArrivalRate > 0 ? 100 - hasArrivalRate : 0" label="到货百分比(%)"
                    @input="inputCheck($event)"></el-input-number>
                </div>
              </div>
              <div class="bottom-item">
                <div class="bottom-label">日期</div>
                <div class="bottom-content">
                  <el-date-picker :disabled="projectLookEditDisabled" v-if="timeSelectStatus" v-model="arrivalTime1"
                    type="date" placeholder="选择日期">
                  </el-date-picker>
                </div>
              </div>

            </div>
          </div>
        </div>
        <div class="adjustOrderItem">
          <div class="adjustOrderItem_left"></div>
          <div class="adjustOrderItem_right"></div>
        </div>
      </div>
      <div class="cost-footer">
        <el-button @click="changeSubmit" style="margin-right: 10px;">取 消</el-button>
        <el-button type="primary" @click="submit" :disabled="sureLoading">确 定</el-button>
      </div>
    </div>
    <div class="" :style="isChange ? 'display: none;' : ''">
      <projectMsg :operationList="operationList" :projectId="chooseId" :isChange="isChange" :showNum="showNumTest">
      </projectMsg>
      <div class="show_project" v-if="operationList.includes('edit')">
        <el-button type="success" @click="changeSubmitGetMsg">编辑</el-button>
        <div v-if="operationList.includes('sureCheckProject') && showMsg.status == 3"></div>
        <el-button type="success" v-if="operationList.includes('sureCheckProject') && showMsg.status == 3"
          @click="doCheck">确认签单</el-button>
        <el-button type="success"
          v-if="operationList.includes('editProjectCheckTime') && checkTime && showMsg.status != 3"
          @click="doEditProjectCheckTime">修改签单时间</el-button>

        <div v-if="operationList.includes('sureFinalProject') && status == 4"></div>
        <el-button type="warning" v-if="operationList.includes('sureFinalProject') && status == 4"
          @click="doSureFinal">确认执行完成</el-button>
      </div>
    </div>

    <el-dialog title="签单时间" :visible.sync="handleClickSureCheckDialog" width="30%"
      :before-close="handleCloseClickSureCheck">
      <el-date-picker v-model="handleClickSureCheckDate" type="datetime" placeholder="选择签单时间" value-format="timestamp">
      </el-date-picker>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClickSureCheckDialog = false">取 消</el-button>
        <el-button type="primary" @click="handleClickSureCheck">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="修改签单时间" :visible.sync="editCheckTimeDialog" width="30%"
      :before-close="handleCloseCheckTimeDialog">
      <el-date-picker v-model="handleEditCheckTime" type="datetime" placeholder="选择签单时间" value-format="timestamp">
      </el-date-picker>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editCheckTimeDialog = false">取 消</el-button>
        <el-button type="primary" @click="saveEditCheckTime">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="执行完成时间" :visible.sync="handleClickSureFinalDialog" width="30%"
      :before-close="handleCloseClickSureFinal">
      <el-date-picker v-model="handleClickSureFinalDate" type="datetime" placeholder="选择执行完成时间">
      </el-date-picker>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClickSureFinalDialog = false">取 消</el-button>
        <el-button type="primary" @click="handleClickSureFinal">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import API from "@/api/apiProject";
import APISysLabel from "@/api/apiSysLabel";
import APIAdmin from "@/api/apiCompanyUser";
import projectMsg from "@/components/ProjectMsg";
import APIBusinessAccount from "@/api/apiBusinessAccount";
import moment from "moment";

export default {
  name: "EditProject",
  components: {
    projectMsg,
  },
  props: {
    operationList: Array,
    isShow: Boolean,
  },
  watch: {
    isChange(val) {
      this.$emit("changeTitle", val);
    },
  },
  data() {
    return {
      arrivalRate: null,
      hasArrivalRate: 0,
      showNumTest: 1,
      userInfo: {},
      chooseId: null,
      status: null,
      projectName: null,
      checkTime: null,
      name: null,
      brands: null,
      brandsUsername: null,
      productName: null,
      cateIdList: null,
      areaIds: null,
      bussinessUsername: null,
      permissionUsername: null,
      invoiceCompany: null,
      invoicePrice: null,
      arrivalInnerPrice: null,
      goodArrivalStatus: null,
      goodArrivalMsg: null,
      cateList: [],
      areaList: [],
      bussinessUserList: [],
      permissionUserList: [],
      invoiceCompanyList: [],
      actualValuePrice: null,
      executionProgressList: [],
      arrivalProgressList: [],
      arrivalWarehouseList: [],
      executionProgressId: null,
      arrivalProgressId: null,
      arrivalWarehouseId: null,
      arrivalTime1: null,
      isChange: false,
      showMsg: {},
      projectRemark: "",
      orderNo: "",
      tableLoading: false,
      brandsList: [],
      brandsChooseList: [],
      brandsPage: 1,
      brandsSize: 10,
      brandsTotal: 10,
      brandsStopLoading: false,
      brandsSearchLoading: false,
      handleClickSureCheckDialog: false,
      handleClickSureCheckDate: null,
      editCheckTimeDialog: false,
      handleEditCheckTime: null,

      sureLoading: false,
      handleClickSureFinalDialog: false,
      handleClickSureFinalDate: null,
      timeSelectStatus: false,
      isDisabled: false,
      projectLookEditDisabled: true,
      chooseBusinessUserId: null,
      querysBrands: '',
    };
  },
  activated() {
    this.isChange = false;
    this.chooseBusinessUserId = null
    this.querysBrands = ''
    this.userInfo = JSON.parse(localStorage.getItem("mujinguserInfo"));
    if (localStorage.getItem("editProject")) {
      let row = JSON.parse(localStorage.getItem("editProject"));
      this.chooseId = row.id;
      this.getMsg();
    }
    this.showNumTest = this.showNumTest + 1;
  },
  created() {
    this.isChange = false;
    if (localStorage.getItem("editProject")) {
      let row = JSON.parse(localStorage.getItem("editProject"));
      // this.showMsg = row
      this.chooseId = row.id;
      // this.getBusinessAccountList(null, this.brandsPage, this.brandsSize);
      this.loadOptionsBrands()
      this.getMsg();
    }
  },
  directives: {
    'el-select-loadmore': {
      bind(el, binding) {
        // 下拉框下拉的框
        const SELECTWRAP_DOM = el.querySelector(
          '.el-select-dropdown .el-select-dropdown__wrap'
        );
        // 增加滚动监听，
        SELECTWRAP_DOM.addEventListener('scroll', function () {
          const condition = this.scrollHeight - this.scrollTop <= this.clientHeight;
          // 当滚动条滚动到最底下的时候执行接口加载下一页
          if (condition) {
            binding.value();
          }
        });
      }
    }
  },
  methods: {
    remoteMethodBrands(query) {
      if (typeof query === 'string') {
        this.querysBrands = query;
      } else {
        this.querysBrands = '';
      }
      this.loadOptionsBrands();
    },
    loadOptionsBrands() {
      //如果需要搜索参数可带入参数this.querys
      // 模拟异步加载数据
      this.brandsSearchLoading = true
      const params = {
        token: this.$store.state.token,
      };
      if (this.userInfo && this.userInfo.role && (this.userInfo.role.includes(40) || this.userInfo.role.includes(55))) {
        params.businessId = this.userInfo.userId;
      }
      if (this.chooseBusinessUserId) {
        params.businessId = this.chooseBusinessUserId;
      }
      if (this.querysBrands) {
        params.keyword = this.querysBrands;
      }
      if (this.brandsPage) {
        params.pageNum = this.brandsPage;
      }
      if (this.brandsSize) {
        params.pageSize = this.brandsSize;
      }
      APIBusinessAccount.getBusinessAccountList(params).then((res) => {
        if (res.key === 1000) {
          this.brandsTotal = res.result.count;
          res = res.result.list;
          var array = res;
          setTimeout(() => {
            // const start = (this.brandsPage - 1) * this.brandsSize;
            // const end = start + this.brandsSize;
            // console.log(list, start, end)
            // let array = list.slice(start, end);
            var finalList = [];
            if (this.brandsPage == 1) {
              finalList = array
            } else {
              finalList = [...this.brandsList, ...array];
            }
            this.brandsList = finalList;
            if (this.brandsList.length == this.total) {
              this.brandsStopLoading = true;
            }
            this.querysBrands = '';
            this.brandsSearchLoading = false
          }, 500);
        }
        this.$bus.$emit("show-loading", false);
      });
    },
    loadMoreBrands() {
      if (!this.brandsStopLoading) {
        this.brandsPage += 1;
        this.loadOptionsBrands();
      }
    },
    arrivalChange(val) {
      console.log(val);
      if (val == "435" || val == "434") {
        this.timeSelectStatus = true;
      } else {
        this.timeSelectStatus = false;
      }
    },
    doGetHasAddProjectName() {
      if (!this.name) {
        return;
      }
      document.querySelector("#asNameInp").style.borderColor = "";
      const params = {
        token: this.$store.state.token,
        name: this.name,
      };
      if (this.chooseId) {
        params.projectId = this.chooseId;
      }
      API.doGetHasAddProjectName(params).then((res) => {
        if (res.key === 1000) {
          let data = res.result.data;
          if (data && data == 2) {
            this.sureLoading = true;
            document.querySelector("#asNameInp").style.borderColor = "red";
          } else {
            this.sureLoading = false;
          }
        }
      });
    },
    getBusinessAccountList(businessId, pageNum, pageSize) {
      this.$bus.$emit("show-loading", true);
      const params = {
        token: this.$store.state.token,
      };
      if (this.userInfo && this.userInfo.role && (this.userInfo.role.includes(40) || this.userInfo.role.includes(55))) {
        params.businessId = this.userInfo.userId;
      }
      if (businessId) {
        params.businessId = businessId;
      }
      if (pageNum) {
        params.pageNum = pageNum;
      }
      if (pageSize) {
        params.pageSize = pageSize;
      }
      APIBusinessAccount.getBusinessAccountList(params).then((res) => {
        if (res.key === 1000) {
          res = res.result.list;
          this.brandsList = res;
        }
        this.$bus.$emit("show-loading", false);
      });
    },
    changeBrands(val) {
      if (val) {
        this.brandsList.forEach((item) => {
          if (item.brandsName == val) {
            this.projectName = item.companyName;
            this.brandsUsername = item.contactPersonName;
          }
        });
      }
    },
    handleClickSureFinalDialogOpen() {
      this.handleClickSureFinalDialog = true;
      this.handleClickSureFinalDate = new Date();
    },
    handleCloseClickSureFinal() {
      this.handleClickSureFinalDialog = false;
      this.handleClickSureFinalDate = null;
    },
    handleClickSureFinal() {
      const params = {
        token: this.$store.state.token,
        projectId: this.showMsg.id,
        chooseDate: this.handleClickSureFinalDate
          ? new Date(this.handleClickSureFinalDate).getTime()
          : null,
      };
      API.doSureFinalProject(params).then((res) => {
        if (res.key === 1000) {
          this.$message({
            type: "success",
            message: "确认成功",
          });
          this.handleCloseClickSureFinal();
          this.getMsg();
        }
      });
    },
    doSureFinal() {
      this.$confirm("此操作将确认执行完该项目, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.handleClickSureFinalDialogOpen();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    handleClickSureCheckDialogOpen() {
      this.handleClickSureCheckDialog = true;
      this.handleClickSureCheckDate = new Date();
    },
    editCheckTimeDialogOpen() {
      this.editCheckTimeDialog = true;
      this.handleEditCheckTime = this.checkTime;
    },
    handleCloseClickSureCheck() {
      this.handleClickSureCheckDialog = false;
      this.handleClickSureCheckDate = null;
    },
    handleCloseCheckTimeDialog() {
      this.editCheckTimeDialog = false;
    },
    handleClickSureCheck() {
      const params = {
        token: this.$store.state.token,
        projectId: this.showMsg.id,
        chooseDate: this.handleClickSureCheckDate
          ? new Date(this.handleClickSureCheckDate).getTime()
          : null,
      };
      API.doSureCheckProject(params).then((res) => {
        if (res.key === 1000) {
          this.$message({
            type: "success",
            message: "确认成功",
          });
          this.handleCloseClickSureCheck();
          this.getMsg();
        }
      });
    },
    saveEditCheckTime() {
      const params = {
        token: this.$store.state.token,
        projectId: this.showMsg.id,
        targetCheckTime: this.handleEditCheckTime
      };
      API.editProjectCheckTime(params).then((res) => {
        if (res.key === 1000) {
          this.$message({
            type: "success",
            message: "修改成功",
          });
          this.handleCloseCheckTimeDialog();
          this.getMsg();
        }
      });
    },
    doCheck() {
      let showErrorMsg = "";
      if (!this.showMsg.name) {
        showErrorMsg = showErrorMsg + "项目名称";
      }
      if (!this.showMsg.projectName) {
        showErrorMsg = showErrorMsg + "客户公司名称";
      }
      if (!this.showMsg.brands) {
        if (showErrorMsg) {
          showErrorMsg = showErrorMsg + ",";
        }
        showErrorMsg = showErrorMsg + "品牌名称";
      }
      if (!this.showMsg.brandsUsername) {
        if (showErrorMsg) {
          showErrorMsg = showErrorMsg + ",";
        }
        showErrorMsg = showErrorMsg + "客户负责人";
      }
      if (!this.showMsg.productName) {
        if (showErrorMsg) {
          showErrorMsg = showErrorMsg + ",";
        }
        showErrorMsg = showErrorMsg + "品名";
      }
      if (!this.showMsg.cates) {
        if (showErrorMsg) {
          showErrorMsg = showErrorMsg + ",";
        }
        showErrorMsg = showErrorMsg + "品类";
      }
      if (!this.showMsg.areas) {
        if (showErrorMsg) {
          showErrorMsg = showErrorMsg + ",";
        }
        showErrorMsg = showErrorMsg + "区域";
      }
      if (!this.showMsg.bussinessUsername) {
        if (showErrorMsg) {
          showErrorMsg = showErrorMsg + ",";
        }
        showErrorMsg = showErrorMsg + "商务";
      }
      if (!this.showMsg.permissionUsername) {
        if (showErrorMsg) {
          showErrorMsg = showErrorMsg + ",";
        }
        showErrorMsg = showErrorMsg + "执行负责人";
      }
      if (!this.showMsg.invoiceCompanyName) {
        if (showErrorMsg) {
          showErrorMsg = showErrorMsg + ",";
        }
        showErrorMsg = showErrorMsg + "开票公司";
      }
      // if(!this.showMsg.invoicePrice){
      //     if(this.showMsg.invoicePrice == 0){
      //     }else{
      //         if(showErrorMsg){
      //             showErrorMsg = showErrorMsg + ','
      //         }
      //         showErrorMsg = showErrorMsg + '开票金额'
      //     }
      // }
      // if (!this.showMsg.goodArrivalStatus) {
      //   if (showErrorMsg) {
      //     showErrorMsg = showErrorMsg + ",";
      //   }
      //   showErrorMsg = showErrorMsg + "到货进度";
      // }
      // if (!this.showMsg.goodArrivalMsg) {
      //   if (showErrorMsg) {
      //     showErrorMsg = showErrorMsg + ",";
      //   }
      //   showErrorMsg = showErrorMsg + "到货详情";
      // }
      // if (!this.showMsg.executionProgressName) {
      //   if (showErrorMsg) {
      //     showErrorMsg = showErrorMsg + ",";
      //   }
      //   showErrorMsg = showErrorMsg + "执行进度";
      // }
      // if (!this.showMsg.arrivalProgressName) {
      //   if (showErrorMsg) {
      //     showErrorMsg = showErrorMsg + ",";
      //   }
      //   showErrorMsg = showErrorMsg + "到货状态";
      // }
      // if (!this.showMsg.orderNo) {
      //   if (showErrorMsg) {
      //     showErrorMsg = showErrorMsg + ",";
      //   }
      //   showErrorMsg = showErrorMsg + "合同编号";
      // }
      if (showErrorMsg) {
        this.$message({
          type: "error",
          message: showErrorMsg + " 未填写，请填写后确认签单",
          duration: 5000,
        });
        return;
      }
      this.$confirm("此操作将确认签单该项目, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.handleClickSureCheckDialogOpen();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    doEditProjectCheckTime() {
      this.$confirm("此操作将修改签单该项目, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.editCheckTimeDialogOpen();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消修改",
          });
        });
    },
    getMsg() {
      this.tableLoading = true;
      const params = {
        token: this.$store.state.token,
        projectId: this.chooseId,
      };
      API.getProjectManageMsg(params).then((res) => {
        if (res.key === 1000) {
          res = res.result;
          let data = res.data;
          if (data.checkTime) {
            data.checkDate = this.formatterTime(data.checkTime);
          }
          if (data.createTime) {
            data.createDate = this.formatterTime(data.createTime);
          }
          if (data.cateIds) {
            let list = [];
            let cateIdList = data.cateIds.split(",");
            cateIdList.forEach((item) => {
              list.push(parseInt(item));
            });
            data.cateIdList = list;
          }
          if (data.areaId) {
            let list = [];
            let idList = data.areaId.split(",");
            idList.forEach((item) => {
              list.push(parseInt(item));
            });
            data.areaIds = list;
          }
          if (
            data.arrivalProgressId == "434" ||
            data.arrivalProgressId == "435"
          ) {
            this.timeSelectStatus = true;

            // data.arrivalTime1 = this.formatterTime(data.arrivalTime)
            // if( data.arrivalProgressId == '435'){
            //     this.isDisabled = true
            // }
          }
          this.showMsg = JSON.parse(JSON.stringify(data));
          this.getSysLabelList();
          this.status = data.status;
          this.checkTime = data.checkTime;
          this.projectName = data.projectName;
          this.name = data.name;
          this.brands = data.brands;
          this.brandsUsername = data.brandsUsername;
          this.productName = data.productName;
          this.cateIdList = data.cateIdList;
          this.areaIds = data.areaId ? parseInt(data.areaId) : null;
          this.bussinessUsername = data.bussinessUsername;
          this.permissionUsername = data.permissionUsername;
          this.invoiceCompany = data.invoiceCompany
            ? parseInt(data.invoiceCompany)
            : null;
          this.invoicePrice = data.invoicePrice;
          this.goodArrivalStatus = data.goodArrivalStatus;
          this.goodArrivalMsg = data.goodArrivalMsg;
          this.actualValuePrice = data.actualValuePrice;
          this.executionProgressId = data.executionProgressId
            ? parseInt(data.executionProgressId)
            : null;
          this.arrivalProgressId = data.arrivalProgressId
            ? parseInt(data.arrivalProgressId)
            : null;
          this.arrivalWarehouseId = data.arrivalWarehouseId
            ? parseInt(data.arrivalWarehouseId)
            : null;
          this.projectRemark = data.projectRemark;
          this.orderNo = data.orderNo;
          this.arrivalTime1 = data.arrivalTime;
          this.hasArrivalRate = data.arrivalRate;

          this.getPermissionUserList();
        }
      });
    },
    formatterTime(time) {
      return this.$moment(time).format("YYYY-MM-DD HH:mm:ss");
    },
    changeSubmitGetMsg() {
      this.getMsg();
      this.showNumTest = this.showNumTest + 1;
      this.changeSubmit();
    },
    changeSubmit() {
      this.isChange = !this.isChange;
      this.$emit("changeTitle", this.isChange);
    },
    changeBusiness(val) {
      if (val) {
        this.chooseBusinessUserId = val
        this.getBusinessAccountList(val, null, null);
      }
    },
    changeArea(val) {
      if (val) {
        let areaName = "";
        this.areaList.forEach((item) => {
          if (item.id == val) {
            areaName = item.sysValueName;
          }
        });
        if (areaName) {
          this.getSysLabelListByAreaKeyword(areaName);
        }
      }
    },
    getSysLabelListByAreaKeyword(keyword) {
      const params = {
        token: this.$store.state.token,
        sysLabelIds: "7",
        keyword: keyword,
      };
      APISysLabel.getSysLabelValueManageList(params).then((res) => {
        if (res.key === 1000) {
          res = res.result;
          if (res.data) {
            this.bussinessUserList = res.data[7];
          }
        }
      });
    },
    getSysLabelList() {
      const params = {
        token: this.$store.state.token,
        sysLabelIds: "2,3,7,12,13,14,18",
      };
      APISysLabel.getSysLabelValueManageList(params).then((res) => {
        if (res.key === 1000) {
          res = res.result;
          if (res.data) {
            this.cateList = res.data[2];
            this.areaList = res.data[3];
            this.bussinessUserList = res.data[7];
            this.executionProgressList = res.data[12];
            this.arrivalProgressList = res.data[13];
            this.arrivalWarehouseList = res.data[14];
            this.invoiceCompanyList = res.data[18];
            if (this.showMsg && this.showMsg.invoiceCompany) {
              this.invoiceCompanyList.forEach((item) => {
                if (item.id == parseInt(this.showMsg.invoiceCompany)) {
                  this.showMsg.invoiceCompanyName = item.sysValueName;
                }
              });
            }
            if (this.showMsg && this.showMsg.executionProgressId) {
              this.executionProgressList.forEach((item) => {
                if (item.id == parseInt(this.showMsg.executionProgressId)) {
                  this.showMsg.executionProgressName = item.sysValueName;
                }
              });
            }
            if (this.showMsg && this.showMsg.arrivalProgressId) {
              this.arrivalProgressList.forEach((item) => {
                if (item.id == parseInt(this.showMsg.arrivalProgressId)) {
                  this.showMsg.arrivalProgressName = item.sysValueName;
                }
              });
            }
            if (this.showMsg && this.showMsg.arrivalWarehouseId) {
              this.arrivalWarehouseList.forEach((item) => {
                if (item.id == parseInt(this.showMsg.arrivalWarehouseId)) {
                  this.showMsg.arrivalWarehouseName = item.sysValueName;
                }
              });
            }
          }
        }
      });
    },
    getPermissionUserList() {
      const params = {
        token: this.$store.state.token,
        roleId: "50,51,61",
      };
      APIAdmin.adminUserList(params).then((res) => {
        if (res.key === 1000) {
          res = res.result;
          this.permissionUserList = res.list;
        }
      });
    },
    inputCheck(e){
        console.log(e)
        if(e > (100-this.hasArrivalRate)){
            this.arrivalRate = 100-this.hasArrivalRate
        }
    },

    submit() {
      const params = {
        id: this.chooseId,
      };
      if (this.executionProgressId) {
        params.executionProgressId = this.executionProgressId;
      }
      if (this.arrivalProgressId) {
        params.arrivalProgressId = this.arrivalProgressId;
      }
      if (this.arrivalWarehouseId) {
        params.arrivalWarehouseId = this.arrivalWarehouseId;
      }
      if (this.actualValuePrice) {
        params.actualValuePrice = this.actualValuePrice;
      }
      if (this.projectName) {
        params.projectName = this.projectName;
      }
      if (this.name) {
        params.name = this.name;
      }
      if (this.brands) {
        params.brands = this.brands;
      }
      if (this.brandsUsername) {
        params.brandsUsername = this.brandsUsername;
      }
      if (this.productName) {
        params.productName = this.productName;
      }
      if (this.invoiceCompany) {
        params.invoiceCompany = this.invoiceCompany;
      }
      if (this.invoicePrice || this.invoicePrice == 0) {
        params.invoicePrice = this.invoicePrice;
      }
      if (this.goodArrivalStatus) {
        params.goodArrivalStatus = this.goodArrivalStatus;
      }
      if (this.goodArrivalMsg) {
        params.goodArrivalMsg = this.goodArrivalMsg;
      }
      if (this.cateIdList && this.cateIdList.length > 0) {
        params.cateIds = this.cateIdList.join(",");
      }
      if (this.areaIds && typeof this.areaIds === "number") {
        params.areaId = this.areaIds + "";
      } else {
        if (this.areaIds && this.areaIds.length > 0) {
          params.areaId = this.areaIds.join(",");
        }
      }
      if (this.bussinessUsername) {
        this.bussinessUserList.forEach((item) => {
          if (item.sysValueName == this.bussinessUsername) {
            params.businessId = item.id;
          }
        });
      }
      if (this.permissionUsername) {
        this.permissionUserList.forEach((item) => {
          if (item.username == this.permissionUsername) {
            params.permissionId = item.id;
          }
        });
      }
      if (this.projectName) {
        params.projectName = this.projectName;
      }
      if (this.name) {
        params.name = this.name;
      }
      if (this.orderNo) {
        params.orderNo = this.orderNo;
      }
      if (this.projectRemark) {
        params.projectRemark = this.projectRemark;
      }
      if (this.arrivalTime1) {
        params.arrivalTime = new Date(this.arrivalTime1);
      }
      if (this.arrivalRate) {
        params.arrivalRate = this.arrivalRate;
      }

      if (100 - this.hasArrivalRate <= 0 && !this.projectLookEditDisabled) {
        this.$message({
          type: "error",
          message: "到货进度进度为100%，已全部到货",
          duration: 5000,
        });
        this.arrivalRate = 100-this.hasArrivalRate
        return;
      }else if(this.projectLookEditDisabled) {
        delete params.arrivalProgressId;
        delete params.arrivalRate;
        delete params.arrivalTime1;
      }
      API.editManageProject(params).then((res) => {
        if (res.key === 1000) {
          this.$message({
            message: "提交成功",
            type: "success",
          });
          if (this.showMsg && this.invoiceCompany) {
            this.invoiceCompanyList.forEach((item) => {
              if (item.id == parseInt(this.invoiceCompany)) {
                this.showMsg.invoiceCompanyName = item.sysValueName;
              }
            });
          }
          if (this.showMsg && this.executionProgressId) {
            this.executionProgressList.forEach((item) => {
              if (item.id == parseInt(this.executionProgressId)) {
                this.showMsg.executionProgressName = item.sysValueName;
              }
            });
          }
          if (this.showMsg && this.arrivalProgressId) {
            this.arrivalProgressList.forEach((item) => {
              if (item.id == parseInt(this.arrivalProgressId)) {
                this.showMsg.arrivalProgressName = item.sysValueName;
              }
            });
          }
          if (this.showMsg && this.arrivalWarehouseId) {
            this.arrivalWarehouseList.forEach((item) => {
              if (item.id == parseInt(this.arrivalWarehouseId)) {
                this.showMsg.arrivalWarehouseName = item.sysValueName;
              }
            });
          }
          if (this.showMsg && this.areaIds) {
            this.areaList.forEach((item) => {
              if (item.id == parseInt(this.areaIds)) {
                this.showMsg.areas = item.sysValueName;
              }
            });
          }
          if (this.showMsg && (this.invoicePrice || this.invoicePrice == 0)) {
            this.showMsg.invoicePrice = this.invoicePrice;
          }
          if (this.showMsg && this.orderNo) {
            this.showMsg.orderNo = this.orderNo;
          }
          if (this.showMsg && this.goodArrivalStatus) {
            this.showMsg.goodArrivalStatus = this.goodArrivalStatus;
          }
          if (this.showMsg && this.goodArrivalMsg) {
            this.showMsg.goodArrivalMsg = this.goodArrivalMsg;
          }
          if (this.showMsg && this.cateIdList && this.cateList) {
            let cates = "";
            this.cateList.forEach((item) => {
              this.cateIdList.forEach((idItem) => {
                if (item.id == parseInt(idItem)) {
                  cates = item.sysValueName + ";";
                }
              });
            });
            this.showMsg.cates = cates;
          }
          this.showNumTest = this.showNumTest + 1;
          // localStorage.setItem("editProject", this.showMsg)
          this.changeSubmit();
        }
      });
    },
    projectLookEditDisabledHandler(type) {
      this.projectLookEditDisabled = type == 1 ? false : true;
    },
  },
};
</script>
<style scoped>
.el-input-number {
  width: 250px !important;
}
.show_project {
  gap: 20px;
  display: flex;
  flex-direction: row;
  justify-content: center;
  margin-bottom: 40px;
  width: 100%;
}
.show_project_msg {
  width: 90%;
}
</style>
<style lang="sass" scoped>
.order-cost-form
    background-color: white
    .cost_item_solid
        border-bottom: 1px solid #e3e3e3
    .cost_item
        width: 95%
        display: flex
        .adjustOrderItem
            margin: 20px auto
            padding-left: 40px
            display: flex
            width: 100%
            .adjustOrderItem_left
                width: 100px
                margin: 11px auto
            .adjustOrderItem_right
                width: 80%
                .show_text
                    margin: 11px auto
    .cost-footer
        padding-left: 100px
        padding-top: 50px
</style>
<style lang="scss" scoped>
.other {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20rpx;
  .other-bottom {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 20px;
    .bottom-item {
      display: flex;
      align-items: center;
      .bottom-label {
        width: 110px;
      }
    }
  }
}
</style>
